/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package byblos.apresentacao;

import byblos.negocio.configuracao.ConfiguracaoEmail;
import byblos.persistencia.DAO;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

/**
 *
 * @author Diego
 */
public class ThreadConnection extends Thread {

    @Override
    public void run() {
        while (true) {
            try { 
                List<ConfiguracaoEmail> lista = new DAO().listar(ConfiguracaoEmail.class);
                getHTML("http://www.byblospousada.com.br/byblos/site.home.logic");
                Thread.sleep(20000);
            } catch (InterruptedException ex) {
                System.out.println("Erro na Thread...");
//                Logger.getLogger(ThreadConnection.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public String getHTML(String urlToRead) {
      URL url; // The URL to read
      HttpURLConnection conn; // The actual connection to the web page
//      BufferedReader rd; // Used to read results from the web page
//      String line; // An individual line of the web page HTML
      String result = ""; // A long string containing all the HTML
      try {
         url = new URL(urlToRead);
         conn = (HttpURLConnection) url.openConnection();
         conn.setRequestMethod("GET");
         new BufferedReader(new InputStreamReader(conn.getInputStream()));
//         while ((line = rd.readLine()) != null) {
//            result += line;
//         }
//         rd.close();
      } catch (Exception e) {
         e.printStackTrace();
      }
      return result;
   }
}
